package com.redwine.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.redwine.app.R;
import com.redwine.app.net.responses.DownOptionsBean;

import java.util.List;


/**
 * 获取地址
 * 作者：gassion on 17/9/5 18:16
 * 最可怕的敌人，就是没有坚强的信念。
 */
public class PersonalInfoAddressAdapter extends BaseAdapter {

    private Context context;

    private List<DownOptionsBean> datalist;


    public PersonalInfoAddressAdapter(Context context) {
        this.context = context;
    }


    /**
     * 下拉加载数据
     *
     * @param datalist
     */
    public void setData(List<DownOptionsBean> datalist) {
        this.datalist = datalist;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        if (null != datalist) {
            return datalist.size();
        } else {
            return 0;
        }
    }

    @Override
    public Object getItem(int position) {
        if (null != datalist) {
            return datalist.get(position);
        } else {
            return null;
        }
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater layoutInflater = LayoutInflater.from(context);
        View view = layoutInflater.inflate(R.layout.activity_personal_info_address_item, parent, false);
        DownOptionsBean downOptionsBean = datalist.get(position);
        TextView tvName = (TextView) view.findViewById(R.id.tv_name);
        tvName.setText(downOptionsBean.getName());
        return view;
    }
}
